package com.ysd.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Date;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.ysd.dao.impl.UserDaoImpl;
import com.ysd.entity.User;
import com.ysd.util.Datetime;
import com.ysd.util.Result;


public class MessageServlet extends HttpServlet {
	
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String username= request.getParameter("username");
		String phone= request.getParameter("phone");
		String email= request.getParameter("email");
		String content= request.getParameter("content");
		Date date = new Date();
		String n1 = Datetime.getToString(date);
		
		User user = new User(username,phone,email,content);
		response.setCharacterEncoding("UTF-8");
		PrintWriter out = response.getWriter();
		//实现类
		UserDaoImpl uDao = new UserDaoImpl();
		int n = uDao.addMessage(user);
		if (n>0) {
			out.print(Result.toClient(true, "成功",""));
		} else {
			out.print(Result.toClient(false, "失败",""));
		}
		
		out.flush();
		out.close();
	}
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
